//
//  UIImage+Extention.swift
//  选择照片
//
//  Created by 李振兴 on 15/11/4.
//  Copyright © 2015年 李振兴. All rights reserved.
//

import UIKit

extension UIImage{

    func scaleImage(width:CGFloat)->UIImage{
        
        if width > size.width {
            return self
        }
        let height = (size.height / size.width) * width
        let rect = CGRectMake(0, 0, width, height)
        UIGraphicsBeginImageContext(rect.size)
        drawInRect(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return image
        
    }
}
